﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TraCuuDiemNhom3.Commons
{
    public class TienIchWeb
    {
        private const string SESSION_USERNAME = "username";
        private const string SESSION_QUYEN = "quyen";
        public static string LayTenDangNhap()
        {
            return (string) HttpContext.Current.Session[SESSION_USERNAME];            
        }
        public static bool DaDangNhap()
        {
            return LayTenDangNhap() != null;                
        }

        public static void GanTenDangNhap(string username)
        {
            HttpContext.Current.Session[SESSION_USERNAME] = username;
        }
        public static List<string> LayDanhSachQuyen()
        {
            if (HttpContext.Current.Session[SESSION_QUYEN] == null)
            {
                HttpContext.Current.Session[SESSION_QUYEN] = new List<string>();
            }
            return (List<string>)HttpContext.Current.Session[SESSION_QUYEN];            
        }
        

        public static void GanQuyen(string maQuyen)
        {
            LayDanhSachQuyen().Add(maQuyen);
        }
        public static bool NguoiDungCoQuyen(string maQuyen)
        {
            return  LayDanhSachQuyen().Contains(maQuyen);                
        }
        public static void XoaThongTinDangNhap()
        {
            HttpContext.Current.Session.Remove(SESSION_USERNAME);
            HttpContext.Current.Session.Remove(SESSION_QUYEN);
        }
    }
}